package net.cassite.daf4j.resource;

import java.io.InputStream;
import java.util.*;

/**
 * mock for source
 */
public class SourceMock implements Source {

        public List<Map<String, Object[]>> invokedMethods = new ArrayList<Map<String, Object[]>>();

        private Map<String, Object[]> getMap(String methodName, Object[] obj) {
                Map<String, Object[]> map = new HashMap<String, Object[]>();
                map.put(methodName, obj);
                return map;
        }

        @Override
        public String separator() throws Exception {
                invokedMethods.add(getMap("separator", new Object[]{}));
                return "/";
        }

        @Override
        public boolean exists(String location) throws Exception {
                invokedMethods.add(getMap("exists", new Object[]{location}));
                return true;
        }

        @Override
        public boolean haveSubLocations(String location) throws Exception {
                invokedMethods.add(getMap("haveSubLocations", new Object[]{location}));
                return true;
        }

        @Override
        public List<String> subLocations(String location) throws Exception {
                invokedMethods.add(getMap("subLocations", new Object[]{location}));
                List<String> list = new ArrayList<String>();
                list.add("subLoc1");
                list.add("subLoc2");
                list.add("subLoc3");
                return list;
        }

        @Override
        public long lastModifiedTime(String location) throws Exception {
                invokedMethods.add(getMap("lastModifiedTime", new Object[]{location}));
                return 233;
        }

        @Override
        public long creatingTime(String location) throws Exception {
                invokedMethods.add(getMap("creatingTime", new Object[]{location}));
                return 234;
        }

        @Override
        public long length(String location) throws Exception {
                invokedMethods.add(getMap("length", new Object[]{location}));
                return 235;
        }

        @Override
        public InputStreamProvider provideStream(String location) throws Exception {
                invokedMethods.add(getMap("provideStream", new Object[]{location}));
                return new InputStreamProvider() {
                        @Override
                        public InputStream get() {
                                return null;
                        }
                };
        }

        @Override
        public void write(String location, InputStream inputStream) throws Exception {
                invokedMethods.add(getMap("write", new Object[]{location, inputStream}));
        }

        @Override
        public void move(String originalLocation, String newLocation) throws Exception {
                invokedMethods.add(getMap("move", new Object[]{originalLocation, newLocation}));
        }

        @Override
        public void delete(Collection<String> locations) throws Exception {
                invokedMethods.add(getMap("delete", new Object[]{locations}));
        }
}
